﻿/*
 *Copyright(C) 2020 by  GYYX All rights reserved.
 *Unity版本：2018.4.23f1 
 *作者:程一峰  
 *创建日期: 2021-04-08 
 *模块说明：
 *版本: 1.2
*/

using Sirenix.OdinInspector;
using Sirenix.Serialization;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace Warfare.FSM
{
    /// <summary>
    /// 状态机节点；
    /// </summary>
    [Serializable]
    public class FSMNode
    {

        protected const string GROUP_BASE = "基本设置";
        protected const string GROUP_SUB = "额外设置";

        #region 节点逻辑部分

        [TitleGroup(GROUP_BASE)]
        [LabelText("当前ID")]
        [DisplayAsString, SerializeField]
        protected int m_Index;

        public virtual int Index
        {
            get => m_Index;
            set => m_Index = value;
        }

        [TitleGroup(GROUP_BASE)]
        [LabelText("取反")]
        [DisplayAsString, SerializeField]
        private bool m_IsTwist;
        public virtual bool IsTwist => m_IsTwist;

        [TitleGroup(GROUP_BASE)]
        [LabelText("成功后节点")]
        [DisplayAsString, SerializeField]
        protected int m_SucessNodeIndex;
        public virtual int SucessNodeIndex
        {
            get => m_SucessNodeIndex;
            set => m_SucessNodeIndex = value;
        }

        [TitleGroup(GROUP_BASE)]
        [LabelText("失败后节点")]
        [DisplayAsString, SerializeField]
        protected int m_FailedNodeIndex;
        public virtual int FailedNodeIndex
        {
            get => m_FailedNodeIndex;
            set => m_FailedNodeIndex = value;
        }

        [LabelText("所有节点行为")]
        [TitleGroup(GROUP_SUB)]
        [OdinSerialize, NonSerialized]
        [ShowInInspector]
        [ListDrawerSettings(ListElementLabelName = "ActionName")]
        public List<FSMNodeAction> Actions = new List<FSMNodeAction>();

        #endregion

        #region 状态机节点描述部分

        [SerializeField, LabelText("状态机描述")]
        private string m_NodeName;
        public virtual string NodeName => string.IsNullOrEmpty(m_NodeName) ? $"运行节点：{m_Index}（{Actions?.Count}）" : m_NodeName;

        public virtual string NodeDescripe { get; set; }
        public virtual string NodeSucessCondition { get; set; }
        public virtual string NodeFailedCondition { get; set; }

        #endregion

        #region 节点绘制部分

        [SerializeField, LabelText("节点位置")]
        [ShowInInlineEditors]
        protected Rect m_NodeRect = new Rect(300, 300, 120, 50);
        public virtual Rect NodeRect => m_NodeRect;

        public virtual void SetNodePosition(Vector3 position) => m_NodeRect.position = position;

        #endregion


    }
}